package com.lanswon.qzsmk.util.pdfutil;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.UnknownHostException;

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileInputStream;

public class RemoteFileTest {
	private static String smburl = "smb://commonuser:Lanswon2018@192.168.0.12/qzsmk/00.temple/"; 
	private static String localPath = "D:\\template\\";
	
	public static void copyFile(String fileName) throws Exception{
		InputStream is = null;
		OutputStream os = null;
		String remoteFileUrl = smburl+fileName;
		String localFileUrl = localPath+fileName;
		try {
			SmbFile remoteFile = new SmbFile(remoteFileUrl);
			if(remoteFile==null){
				System.out.println("共享文件不存在！");
			}
			File localFile = new File(localFileUrl);
			is = new BufferedInputStream(new SmbFileInputStream(remoteFile));
			os = new BufferedOutputStream(new FileOutputStream(localFile));
			byte[] buffer = new byte[1024];
			int len;
			while((len=is.read(buffer))!=-1){
				os.write(buffer, 0, len);
			}
			os.flush();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try{
				if(os!=null){
					os.close();
				}
				if(is!=null){
					is.close();
				}
			}catch(IOException e){
				e.printStackTrace();
			}
		}
		
	}
	
	
	public static void main(String args[]){
		String fileName = "receive123456_print.pdf";
		try {
			copyFile(fileName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
